import {
  OrderPageParams,
  PriceParams,
  SaaSOrderListItem,
  SaaSOrderPostForm,
  SaaSRegionTreeItem,
} from './model/orderModel';
import { orderHttp } from '/@/utils/http/axios';

enum Api {
  SaaSOrderList = '/order/getList',
  SaaSOrderCreateOrUpdate = '/order/createOrUpdate',
  SaaSRegionTree = '/regionTree/getChina',
  SaaSOrderDelete = '/order/delete/',
  SaaSCommodityPrice = '/order/getPriceById',
}

export const getSaaSOrderList = (params: OrderPageParams) => {
  // 获取商品列表
  params.model = {
    orderId: params.orderId || '',
    commodityName: params.commodityName || '',
    customer: params.customer || '',
    startCreatedTime: params.startCreatedTime || '',
    endCreatedTime: params.endCreatedTime || '',
  };
  return orderHttp.post<SaaSOrderListItem>({ url: Api.SaaSOrderList, params });
};

export const createOrUpdateSaaSOrder = (params: SaaSOrderPostForm) => {
  // 创建商品 - 提交表单
  return orderHttp.post<string>({ url: Api.SaaSOrderCreateOrUpdate, params });
};

export const deleteSaaSOrder = (params: string) => {
  // 删除订单 - 订单ID：
  return orderHttp.delete<string>({ url: Api.SaaSOrderDelete + params });
};

export const getRegionList = () => {
  return orderHttp.get<SaaSRegionTreeItem>({ url: Api.SaaSRegionTree });
};

export const getCommodityPrice = (params: PriceParams) => {
  // 获取商品单价
  return orderHttp.get<string>({ url: Api.SaaSCommodityPrice, params });
};
